/* $Header: sig_types.h,v 2.5 02/04/25 13:23:23 przybyls Exp $ */

/***********************************************************************/
/* INCLUDE FILE NAME:  sig_types.h                                     */
/* ==================                                                  */
/*                                                                     */
/* Author:   Lesley Freed                                              */
/*                                                                     */
/* COMMENT: This file contains all of the local typedefs used in the   */
/*          signal path for IQ.                                        */
/*                                                                     */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

#ifndef SIG_TYPE_H
#define SIG_TYPE_H

/*****************************/
/*   IFDEFS                  */
/*****************************/


/*****************************/
/*   SYMBOLIC CONSTANTS      */
/*****************************/

#define ARRAY_SIZE_3HZ  16      /* 3 Hz 16-point box car filter array for attn*/
#define DAC_ARRAY_SIZE_3HZ  32  /* 3 Hz 32-point box car filter array for DAC */
#define ARRAY_SIZE_SIG_DISP 10  /* Signal display box car filter array        */
#define ARRAY_SIZE_SCC_DET  50  /* Scc detector data box car filter array     */

/* Active Workfile Setpoint Masks */

/* bit 0: */
#define ZERO_ON_MASK    0x01    /* mask to check zero on/off bit (1=on)       */
#define ZERO_OFF_MASK   0xfe    /* mask to check zero on/off bit (1=on)       */

/* bit 1: */
#define ATTN_ON_MASK    0x02    /* mask to check attn on/off bit (1=on)       */
#define ATTN_OFF_MASK   0xfd    /* mask to check attn on/off bit (1=on)       */

/* bit 2: */
#define DIG_ZERO_ON_MASK  0x04  /* mask to enable zero subtract  (1=on)       */
#define DIG_ZERO_OFF_MASK 0xfb  /* mask to disable zero subtract (1=on)       */

/* bit 5: */
#define FREEZE_SIG_ON_MASK  0x20        /* mask to enable sig freeze  (1=on)      */
#define FREEZE_SIG_OFF_MASK 0xDF        /* mask to disable sig freeze             */

/* bit 6: */
#define RESUME_SIG_ON_MASK  0x40        /* mask to enable sig resume&reset(1=on)  */
#define RESUME_SIG_OFF_MASK 0xBF        /* mask to disable sig resume&reset       */

/* bit 7: */
#define RESUM2_SIG_ON_MASK  0x80        /* mask to enable sig resume&reset(1=on)  */
#define RESUM2_SIG_OFF_MASK 0x7F        /* mask to disable sig resume&reset       */

#define FREEZE_RESUME_MASK  0x60        /* mask to chk both resume&freeze         */
#define RESUM2_RESUME_MASK  0xC0        /* mask to chk both resume&resum2         */
#define RESUMEX_FRZ_ON_MSK  0xE0    /* to chk any of the 3 bits               */
#define RESUMEX_FRZ_OFF_MSK 0x1F    /* clrs ALL frz&resume bits               */

/********************/
/* SCC  Definitions */
/********************/

#define LAST_SCC_SEGMENT              100
#define NO_OF_SIGNALS_PER_SUBSEGMENT  3

#define INIT_TEST_PLOT_SCALE_FACTOR   100
#define COL_COMP_SCALE_FACTOR         1


/**************************************************************************/
/*                                                                        */
/* We want the minimum run length for SCC that we can break up evenly     */
/* into 100 segments.                                                     */
/*                                                                        */
/* We need a run length that is at least long enough to give us one sub-  */
/* segment per segment.  The subsegment is of length:                     */
/*                                                                        */
/*          NO_OF_SIGNALS_PER_SUBSEGMENT * .01 seconds per signal         */
/*                                                                        */
/* Thus the minimun run length for SCC is of length:                      */
/*                                                                        */
/*          NO_OF_SIGNALS_PER_SUBSEGMENT * .01 seconds per signal * 100   */
/*                                                                        */
/* Need run length minimum in units of hundredths of a minute (cmin):     */
/*                                                                        */
/* (minimum run length in seconds) * (1 min/60 sec) * 100 (cmin/min)      */
/*                                                                        */
/**************************************************************************/

/*      MIN_SCC_RUN_TIME = 100*NO_OF_SIGNALS_PER_SUBSEGMENT/60 = 17       */
/*  NOTE:  Since we subtract SLACK_TIME from the run length before        */
/*         calculating the scc run time (so we can collect the last data  */
/*         point during RUN_ACTIVE) we will make the minimum scc run time */
/*         on .01 min longer than the calculated minimum.                 */

#define MIN_SCC_RUN_TIME (17+1)

#define SLACK_TIME 40  /* milliseconds subtracted from run length for scc */
                       /* collect to ensure that the last data point is   */
                       /* collected during RUN_ACTIVE.                    */

/*****************************/
/*   MACROS                  */
/*****************************/


/*****************************/
/*   TYPEDEFS                */
/*****************************/

/* Define enummerated types for Single Column Compensation */

typedef enum
{
   /* WARNING:  do not change these enumeration values, as datacomm assumes them */
   CCOMP1   = 1,
   CCOMP2   = 2,
   CCOMP1_2 = 3

} CCOMP;

typedef enum
{
   CCOMP1_TYPE,
   CCOMP2_TYPE,
   TEST_SIGNAL_TYPE,
   TEST_PLOT_TYPE

} CCOMP_TYPE;

typedef enum
{
   COLLECT_OFF  = 0,
   COLLECT_WAIT = 1,
   COLLECT_ON   = 2

} SCC_COLLECT_STATE;

typedef enum
{
   DISABLE_CCOMP      = 0,
   ADD_CCOMP1         = 1,
   ADD_CCOMP2         = 2,
   SUBTRACT_CCOMP1    = 3,
   SUBTRACT_CCOMP2    = 4,
   EXPAND_TEST_PLOT   = 5,
   EXPAND_TEST_SIGNAL = 6

} CCOMP_MODE;

typedef enum
{
   NO_DATA         = 0,
   DATA_OK         = 1,
   INCOMPLETE_DATA = 2

} SCC_DATA_STATE;

/**********************/
/* Digital data types */
/**********************/


typedef struct
{
   DIG_DATA output;          /* 48-bit signal result of bunching         */
   U_INT32  remainder;       /* 32-bit remainder result of bunching      */

} BUNCH_OUT, *pBUNCH_OUT;

/* signal conversion mode */

typedef enum
{
   NULL_CONV      = 0,
   CONV_uECD_LIN  = 1,
   CONV_uECD_TEST = 2,
   CONV_LDID_LIN  = 3,
   CONV_LDID_TEST = 4

} SIG_CONV;

/***************************/
/* Signal Type Definitions */
/***************************/

/* Signal unit:  the number of significant digits past the decimal point.  */
/* For example, 2.340 has 3 significant digits past the decimal point and  */
/* 2.34 has 2.  This is used by the signal display routines -and- the      */
/* datacomm command reporting scaling information.                         */

typedef enum
{
   SIGNAL_UNSCALED = 0,
   SIGNAL_DET      = 1,
   SIGNAL_D2       = 2,
   SIGNAL_D3       = 3,
   SIGNAL_D4       = 4

} SIG_UNITS;

/* Note:  The following signal type is used only by the signal DSP to flag it */
/*        to set the signal to zero if the respective detector is turned off  */
#define ZERO_SIGNAL 4

typedef enum
{
        /* Detector Type Signal Definitions */
                                                                                   /*          Decimal        Scale  */
                                                                                   /* Units    Significance   Factor */
                                                                                   /* -----    ------------   ------ */
        DETA_SIGNAL   = 0,               /* detector A                        */   /*  pA      XXXXXXX.X       240   */
        DETB_SIGNAL   = 1,               /* detector B                        */   /*  pA      XXXXXXX.X       240   */
        DETA_B_SIGNAL = 2,               /* detector A - detector B           */   /*  pA      XXXXXXX.X       240   */
        DETB_A_SIGNAL = 3,               /* detector B - detector A           */   /*  pA      XXXXXXX.X       240   */

        /* Column Compensation Signals      */

        COL_COMP1_SIGNAL = 4,            /* column comp 1 profile             */   /*  pA      XXXXXXX.X       240   */
        COL_COMP2_SIGNAL = 5,            /* column comp 2 profile             */   /*  pA      XXXXXXX.X       240   */
        F_CCOMP1_SIGNAL  = 6,            /* front - column comp 1 profile     */   /*  pA      XXXXXXX.X       240   */
        B_CCOMP1_SIGNAL  = 7,            /* back - column comp 1 profile      */   /*  pA      XXXXXXX.X       240   */
        F_CCOMP2_SIGNAL  = 8,            /* front - column comp 2 profile     */   /*  pA      XXXXXXX.X       240   */
        B_CCOMP2_SIGNAL  = 9,            /* back - column comp 2 profile      */   /*  pA      XXXXXXX.X       240   */
        TEST_PLOT_SIGNAL = 10,           /* Test Plot                         */   /*  pA      XXXXXXX.X       240   */
        TEST_SIGNAL_SIGNAL = 11,         /* Ramp signal                       */   /*  arbs    XXXXXXX.X       240   */

        /* Alternate Signals Type Definitions */

/* 32-bit Signals */

        OVEN_TEMP_SIGNAL = 12,           /* oven temperature                  */   /*  deg C       XXX.X       240      */
        DETA_TEMP_SIGNAL = 13,           /* detector A temperature            */   /*  deg C       XXX.X       240      */
        DETB_TEMP_SIGNAL = 14,           /* detector B temperature            */   /*  deg C       XXX.X       240      */
        INJA_TEMP_SIGNAL = 15,           /* injector A temperature            */   /*  deg C       XXX.X       240      */
        INJB_TEMP_SIGNAL = 16,           /* injector B temperature            */   /*  deg C       XXX.X       240      */

        AUXA_TEMP_SIGNAL = 17,           /* auxilliary A temperature          */   /*  deg C       XXX.X       240      */
        AUXB_TEMP_SIGNAL = 18,           /* auxilliary B temperature          */   /*  deg C       XXX.X       240      */

        COL1_FLOW_SIGNAL = 19,           /* column 1 volumetric flow          */   /*  ml/min      XXX.X       240      */
        COL2_FLOW_SIGNAL = 20,           /* column 2 volumetric flow          */   /*  ml/min      XXX.X       240      */
        COL1_PRES_SIGNAL = 21,           /* column 1 head pressure            */   /*  PSI         XXX.X       240      */
        COL2_PRES_SIGNAL = 22,           /* column 2 head pressure            */   /*  PSI         XXX.X       240      */
        F_INLET_FLOW_SIGNAL = 23,        /* filtered current total flow       */   /*  ml/min      XXX.X       240      */
        B_INLET_FLOW_SIGNAL = 24,        /* filtered current total flow       */   /*  ml/min      XXX.X       240      */
        F_INLET_PRES_SIGNAL = 25,        /* filtered current pressure         */   /*  PSI         XXX.X       240      */
        B_INLET_PRES_SIGNAL = 26,        /* filtered current pressure         */   /*  PSI         XXX.X       240      */
        F_DET_GAS1_PRES_SIGNAL = 27,     /* front det gas 1 pressure          */   /*  PSI         XXX.X       240      */
        F_DET_GAS2_PRES_SIGNAL = 28,     /* front det gas 2 pressure          */   /*  PSI         XXX.X       240      */
        F_DET_GAS3_PRES_SIGNAL = 29,     /* front det gas 3 pressure          */   /*  PSI         XXX.X       240      */
        B_DET_GAS1_PRES_SIGNAL = 30,     /* back det gas 1 pressure           */   /*  PSI         XXX.X       240      */
        B_DET_GAS2_PRES_SIGNAL = 31,     /* back det gas 2 pressure           */   /*  PSI         XXX.X       240      */
        B_DET_GAS3_PRES_SIGNAL = 32,     /* back det gas 3 pressure           */   /*  PSI         XXX.X       240      */
        F_DET_GAS1_FLOW_SIGNAL = 33,     /* front det gas 1 flow              */   /*  ml/min      XXX.X       240      */
        F_DET_GAS2_FLOW_SIGNAL = 34,     /* front det gas 2 flow              */   /*  ml/min      XXX.X       240      */
        F_DET_GAS3_FLOW_SIGNAL = 35,     /* front det gas 3 flow              */   /*  ml/min      XXX.X       240      */
        B_DET_GAS1_FLOW_SIGNAL = 36,     /* back det gas 1 flow               */   /*  ml/min      XXX.X       240      */
        B_DET_GAS2_FLOW_SIGNAL = 37,     /* back det gas 2 flow               */   /*  ml/min      XXX.X       240      */
        B_DET_GAS3_FLOW_SIGNAL = 38,     /* back det gas 3 flow               */   /*  ml/min      XXX.X       240      */
        AUX_3_PRES_SIGNAL = 39,          /* aux #3 filtered current pressure  */   /*  PSI         XXX.X       240      */
        AUX_4_PRES_SIGNAL = 40,          /* aux #4 filtered current pressure  */   /*  PSI         XXX.X       240      */
        AUX_5_PRES_SIGNAL = 41,          /* aux #5 filtered current pressure  */   /*  PSI         XXX.X       240      */

        MUX_ADC_OFFSET_SIGNAL = 42,     /* the mux'ed adc offset              */   /*  volts      X.XXXX       240000   */

        OVEN_RTD_RDG_SIGNAL = 43,       /* filtered rtd reading for the oven  */   /*  volts      X.XXXX       240000   */
        DETA_RTD_RDG_SIGNAL = 44,       /* filtered rtd reading for frnt det  */   /*  volts      X.XXXX       240000   */
        DETB_RTD_RDG_SIGNAL = 45,       /* filtered rtd reading for back det  */   /*  volts      X.XXXX       240000   */
        INJA_RTD_RDG_SIGNAL = 46,       /* filtered rtd reading for frnt inl  */   /*  volts      X.XXXX       240000   */
        INJB_RTD_RDG_SIGNAL = 47,       /* filtered rtd reading for back inl  */   /*  volts      X.XXXX       240000   */
        AUXA_RTD_RDG_SIGNAL = 48,       /* filtered rtd reading for aux #1    */   /*  volts      X.XXXX       240000   */
        AUXB_RTD_RDG_SIGNAL = 49,       /* filtered rtd reading for aux #2    */   /*  volts      X.XXXX       240000   */

        ATTN1_SIGNAL = 50,              /* Attenuator 1 output fed back to adc */  /*  volts      X.XXXX       240000   */
        ATTN2_SIGNAL = 51,              /* Attenuator 2 output fed back to adc */  /*  volts      X.XXXX       240000   */
        DAC1_SIGNAL = 52,               /* DAC 1 output fed back to mux adc    */  /*  volts      X.XXXX       240000   */
        DAC2_SIGNAL = 53,               /* DAC 2 output fed back to mux adc    */  /*  volts      X.XXXX       240000   */

        MON_5V_SIGNAL = 54,             /* +5V monitor signal                 */   /*  volts       X.XXX        24000   */
        MON_24V_SIGNAL = 55,            /* +24V monitor signal                */   /*  volts       X.XXX        24000   */
        MON_15VPOS_SIGNAL = 56,         /* +15V monitor signal                */   /*  volts       X.XXX        24000   */
        MON_15VNEG_SIGNAL = 57,         /* -15V monitor signal                */   /*  volts       X.XXX        24000   */

        DET_DIAGA_SIGNAL = 58,          /* front detector Vout 1 diagnostic   */   /*  volts      X.XXXX       240000   */
        DET_DIAGB_SIGNAL = 59,          /* front detector Vout 2 diagnostic   */   /*  volts      X.XXXX       240000   */
        DET_DIAGC_SIGNAL = 60,          /* back detector Vout 1 diagnostic    */   /*  volts      X.XXXX       240000   */
        DET_DIAGD_SIGNAL = 61,          /* back detector Vout 2 diagnostic    */   /*  volts      X.XXXX       240000   */

        ATM_PRES_SIGNAL        = 62,    /* atmospheric pressure               */   /*  psia       X.XXXX       240000   */
        F_INL_MOD_TEMP_SIGNAL  = 63,    /* atmospheric pressure               */   /*  psia       X.XXXX       240000   */
        B_INL_MOD_TEMP_SIGNAL  = 64,    /* atmospheric pressure               */   /*  psia       X.XXXX       240000   */
        F_DET_MOD_TEMP_SIGNAL  = 65,    /* atmospheric pressure               */   /*  psia       X.XXXX       240000   */
        B_DET_MOD_TEMP_SIGNAL  = 66,    /* atmospheric pressure               */   /*  psia       X.XXXX       240000   */
        AUX_MOD_TEMP_SIGNAL    = 67,    /* atmospheric pressure               */   /*  psia       X.XXXX       240000   */
        PNEU_10V_SIGNAL        = 68,    /* atmospheric pressure               */   /*  psia       X.XXXX       240000   */
        PNEU_ADC_OFFSET_SIGNAL = 69,    /* atmospheric pressure               */   /*  psia       X.XXXX       240000   */
        F_INL_GAS_VOLTS_SIGNAL = 70,    /* atmospheric pressure               */   /*  psia       X.XXXX       240000   */
        B_INL_GAS_VOLTS_SIGNAL = 71,    /* atmospheric pressure               */   /*  psia       X.XXXX       240000   */

/* For diagnostics only */
        F_INLET_FLOW_SETPT_SIGNAL = 72, /* filtered current total flow setpt */   /*  ml/min      XXX.X       240      */
        B_INLET_FLOW_SETPT_SIGNAL = 73, /* filtered current total flow setpt */   /*  ml/min      XXX.X       240      */
        F_INLET_PRES_SETPT_SIGNAL = 74, /* filtered current pressure setpt   */   /*  PSI         XXX.X       240      */
        B_INLET_PRES_SETPT_SIGNAL = 75, /* filtered current pressure setpt   */   /*  PSI         XXX.X       240      */
        F_D_GAS1_P_SETPT_SIGNAL = 76,   /* front det gas 1 pressure setpt    */   /*  PSI         XXX.X       240      */
        F_D_GAS2_P_SETPT_SIGNAL = 77,   /* front det gas 2 pressure setpt    */   /*  PSI         XXX.X       240      */
        F_D_GAS3_P_SETPT_SIGNAL = 78,   /* front det gas 3 pressure setpt    */   /*  PSI         XXX.X       240      */
        B_D_GAS1_P_SETPT_SIGNAL = 79,   /* back det gas 1 pressure setpt     */   /*  PSI         XXX.X       240      */
        B_D_GAS2_P_SETPT_SIGNAL = 80,   /* back det gas 2 pressure setpt     */   /*  PSI         XXX.X       240      */
        B_D_GAS3_P_SETPT_SIGNAL = 81,   /* back det gas 3 pressure setpt     */   /*  PSI         XXX.X       240      */
        F_D_GAS1_F_SETPT_SIGNAL = 82,   /* front det gas 1 flow setpt        */   /*  ml/min      XXX.X       240      */
        F_D_GAS2_F_SETPT_SIGNAL = 83,   /* front det gas 2 flow setpt        */   /*  ml/min      XXX.X       240      */
        F_D_GAS3_F_SETPT_SIGNAL = 84,   /* front det gas 3 flow setpt        */   /*  ml/min      XXX.X       240      */
        B_D_GAS1_F_SETPT_SIGNAL = 85,   /* back det gas 1 flow setpt         */   /*  ml/min      XXX.X       240      */
        B_D_GAS2_F_SETPT_SIGNAL = 86,   /* back det gas 2 flow setpt         */   /*  ml/min      XXX.X       240      */
        B_D_GAS3_F_SETPT_SIGNAL = 87,   /* back det gas 3 flow setpt         */   /*  ml/min      XXX.X       240      */
        AUX_3_PRES_SETPT_SIGNAL = 88,   /* aux #3 filtered pressure setpt    */   /*  PSI         XXX.X       240      */
        AUX_4_PRES_SETPT_SIGNAL = 89,   /* aux #4 filtered pressure setpt    */   /*  PSI         XXX.X       240      */
        AUX_5_PRES_SETPT_SIGNAL = 90,   /* aux #5 filtered pressure setpt    */   /*  PSI         XXX.X       240      */

        END_OF_SCALED_SIGNALS = 91,

/********************/
/* Unscaled Signals */
/********************/

        RAW_ADC_RDG_SIGNAL = 100,        /* individual readings from mux adc  */
        RAW_RDG_NOISE_SIGNAL = 101,      /* noise of selected adc channel     */

        MUX_ADC_NOISE_SIGNAL = 102,      /* noise for the mux'ed adc offset   */

        LINE_SENSE_SIGNAL = 103,         /* line power input sense            */

        DETA_1ST_ORDER_SIG = 104,        /* detector A 1st order rdg signal   */
        DETB_1ST_ORDER_SIG = 105,        /* detector B 1st order rdg signal   */
        DETA_2ND_ORDER_SIG = 106,        /* detector A 2nd order rdg signal   */
        DETB_2ND_ORDER_SIG = 107,        /* detector B 2nd order rdg signal   */
        DETA_DATA_SIG = 108,             /* detector A data before select and */
                                         /* combine within DSP                */
        DETB_DATA_SIG = 109,             /* detector B data before select and */
                                         /* combine within DSP                */
        DETA_OFFSET_SIG = 110,           /* detector A offset reading         */
        DETB_OFFSET_SIG = 111,           /* detector B offset reading         */


/*****************************************************/
/* Flag indicating end of supported signal type list */
/* Note: CheckSignalType rejects anything greater    */
/*       than or equal to END_OF_SIGNALS as a type.  */
/*****************************************************/

        END_OF_SIGNALS = 112,

        MEMORY_LOCATION = 252,           /* value stored in address,          */
                                         /* mem_location of 8,16, or 32-bit   */
                                         /* data size                         */


/* Flags for Mode table under signal key */

        THERMAL_SIGNALS = 253,
        PNEUMATIC_SIGNALS = 254,
        DIAGNOSTIC_SIGNALS = 255

} SIG_TYPE;

#define FIRST_SIGNAL_TYPE      DETA_SIGNAL
#define FIRST_ALTERNATE_SIGNAL OVEN_TEMP_SIGNAL   /* 1st plot type signal */
#define FIRST_UNSCALED_SIGNAL  RAW_ADC_RDG_SIGNAL /* 1st unscaled signal */

/* Declare min and max.s */

#define MAX_DSP_SIGNAL_TYPE TEST_SIGNAL_SIGNAL    /* Max signal value from the*/
                                                  /* detector dsp             */
#define MAX_DET_SIGNAL_TYPE TEST_SIGNAL_SIGNAL    /* Max value for a detector */
                                                  /* type signal              */

typedef enum
{
   NOT_IN_RUN,
   START_PENDING,
   RUN_IN_PROGRESS,
   STOP_PENDING,
   STOP_PENDING2

} SIG_RUN_STATE;

typedef struct
{
        INT32     multiplier;
        INT32     divisor;
        SIG_UNITS units;
        char  const *plabel;

} SCALE_CONSTANTS, *pSCALE_CONSTANTS;

typedef struct
{
        INT32 offset;
        INT32 multiplier;
        INT32 divisor;

} PLOT_CONSTANTS, *pPLOT_CONSTANTS;

typedef struct
{
        U_INT32         *addr;
        PLOT_CONSTANTS  const *pconstants;
        DATA_SIZE       size;
        SCALE_CONSTANTS const *pscale;

} PLOT_INFO;

/* Diagnostic type 'unscaled' signal plot information */
typedef struct
{
        U_INT32         *addr;
        DATA_SIZE       size;

} UNSCALED_PLOT_INFO;

/* The following structure is used to store the data needed to maintain a     */
/* signal, such as WORKING SETPOINTS, box car filter storage, ranging and     */
/* bunching remainders.                                                       */

typedef struct
{
        U_INT32 quotient;         /* Quotient             (returned in d0)    */
        U_INT32 remainder;        /* Remainder            (returned in d1)    */
} LDIV_TYPE;

typedef struct
{
        U_INT8  output;           /* MSB of 16-bit ATTN data                  */
        U_INT8  remainder;        /* LSB Remainder of ATTN data               */
} ATTN_TYPE;

typedef struct
{
/* Working Copies of Signal Setpoints */

   U_INT8          chan;                    /* signal channel #               */
   SIG_TYPE        signal;                  /* signal definition              */
   DATA_SIZE       plot_size;               /* word size of the data to plot  */
   U_INT32         *plot;                   /* pointer to plot data           */
   INT32           plot_out;                /* plot out data                  */
   PLOT_CONSTANTS  const *pconstants;       /* pointer to offset, multiplier  */
                                            /* & divisor to apply to plot data*/
   SCALE_CONSTANTS const *pscale;           /* pointer to multiplier, divisor */
                                            /* & label to convert signal to   */
                                            /* meaningful units.              */
   SIG_TYPE        more_signal[4];          /* additional signals for Signal2 */
   DATA_SIZE       more_plot_size[4];
   U_INT32         *more_plot[4];
   INT32           more_plot_out[4];
   PLOT_CONSTANTS  const *more_pconstants[4];
   SCALE_CONSTANTS const *more_pscale[4];
   U_INT16         next_plot_out;           /* cycle through the signal(s)    */
   INT32           zero;                    /* signal zero                    */
   INT32           stored_value;            /* stored value used to calc zero */
   U_INT8          range;                   /* signal analog range            */
   U_INT8          attn;                    /* signal analog attenuation      */
   CCOMP_MODE      ccomp_mode;              /* column compensation mode       */
   BIT8            zero_attn_on_off;

/***********************/
/*                     */
/* Analog Signal Path  */
/*                     */
/***********************/

/* Filters, Ranging, Bunching Data */

        /* Analog Ranging and Attenuation */
        U_INT8  range_rem;                  /* remainder from ranging signal  */
        U_INT8  attn_rem;                   /* remainder from attenuating sig */

        /* Zero entry and signal display filter */
        INT32     filt_table[ARRAY_SIZE_SIG_DISP];
        BUNCH_SUM filt_sum;
        BUNCH_OUT32 filt_out;
        U_INT8    ptr_filt;                 /* pointer to last data point in  */
                                            /* boxcar data array              */

/* DAC 3 Hz Filter */
        U_INT8  ptr_filter_3_DAC;           /* pointer to last data point in  */
                                            /* boxcar data array              */
        U_INT32 filter_3_DAC[DAC_ARRAY_SIZE_3HZ]; /* n-pt box car data array  */
        U_INT32 filter_sum_3_DAC;           /* 3 Hz boxcar filter running sum */

/* DAC Filter Output */
        LDIV_TYPE filter_out_DAC;           /* Boxcar filter output and       */
                                            /* remainder                      */
/* DAC Output */
        U_INT32   DAC_out;                  /* Output data for Detector DSP   */

/* ATTN 3 Hz Filter */
        U_INT8  ptr_filter_3_ATTN;           /* pointer to last data point in */
                                             /* boxcar array data             */
        U_INT32 filter_3_ATTN[ARRAY_SIZE_3HZ]; /* 16-pt box car data array    */
        U_INT32 filter_sum_3_ATTN;           /* 3 Hz boxcar fltr running sum  */
        LDIV_TYPE filter_out_ATTN;           /* 3 Hz fltr output and remainder*/

/* ATTN Output */
        ATTN_TYPE ATTN_out;                  /* 16-bit ATTN output and        */
                                             /* remainder                     */
/***********************/
/*                     */
/* Digital Signal Path */
/*                     */
/***********************/

        /* Digital Bunched Data */
        BUNCH_SUM bunch_sum;                 /* 64-bit running sum for bunch  */
        BUNCH_SUM filt_bunch_sum;            /* sum of 3 bunch sums for boxcar*/
        BUNCH_SUM bunch_table[3];            /* array of last 3 bunch sums    */
        INT16     bunch_index;               /* ptr to next available location*/

        BUNCH_OUT bunch_out;                 /* 48-bit result of bunch and    */
                                             /* 32-bit remainder              */

        /* Digital Output Data */
/*      DIG_DATA  dig_data[5];      */       /* 48-bit digital data           */
        DIG_DATA  dig_data[8];               /* 48-bit digital data           */

        U_INT8    bunch_count;               /* # of data pts bunched         */
        BIT8      bunch_reset;               /* flag to reset the bunch filter*/

        SIG_CONV  sig_conv_mode;             /* type of conversion for data   */
        INT32     conv_analog;               /* last converted analog data pt */
/* Start and Stop Run Data */

        SIG_RUN_STATE run_state;             /* state of the signal stream    */

        U_INT32 start_run_count;             /* # of 62.5 usec time intervals */
                                             /* from start run to 1st data pt */
        BIT16   stop_run_marker;             /* flag indicating stop received */
                                             /* but stop marker not inserted  */

/* Pointers to Active Workfile setpts and Signal DSP input data */

        SIG_SETPTS *active_wkfile;           /* ptr to active workfile setpts */

        SIG_IN     *dsp_data;                /* ptr to input data from dsp    */

/* Diagnostic data */

        INT32   last_reading;         /* latest value in analog signal path */
        INT32   max_reading;
        INT32   min_reading;
        U_INT32 noise;
        U_INT16 reading_count;

} SIG_TABLE, *pSIG_TABLE;             /* structure type name for signal table */


/* Lookup type for converting from data rate to dsp data rate and bunch count */

typedef enum
{
  RATE_PT1HZ  = 0,
  RATE_PT2HZ  = 1,
  RATE_PT5HZ  = 2,
  RATE_1HZ    = 3,
  RATE_2HZ    = 4,
  RATE_5HZ    = 5,
  RATE_10HZ   = 6,
  RATE_20HZ   = 7,
  RATE_50HZ   = 8,
  RATE_100HZ  = 9,
  RATE_200HZ  = 10,
  RATE_500HZ  = 11

} RATE_TYPE;

typedef struct
{
   BIT8      rate;
   U_INT8    bunch_count;

} RATE_REC;

/* Column compensation profile data, this is power-fail protected.            */

typedef struct
{
   SCC_DATA_STATE data_valid_flag;  /* flag indicating whether or not there   */
                                    /* is data                                */
   POSITION det_data_stored;  /* detector position for stored scc data        */
   DET_TYPE det_type;         /* type  of detector for stored data            */
   U_INT16  Nstd;             /* # of 100 Hz signal points between standard   */
                              /* interpolation data points                    */
   U_INT16  Nlast;            /* # of 100 Hz signal points between last two   */
                              /* interpolation data points                    */
   U_INT16  Mstd;             /* # of subsegments between interpolation pts.  */
   U_INT16  Mlast;            /* # of subsegments between last two inter. pts.*/
   DATETIME datetime;         /* date and time profile was stored             */
} CCOMP_DATA, *pCCOMP_DATA;   /* struct name for column comp data            */

typedef INT32 PROFILE[ LAST_SCC_SEGMENT+2 ];

/* Working setpts and var.s for column compensation, not power-fail protected */

typedef struct
{

   BIT8       collect_scc_flag; /* flag to initiate scc profile collection    */
   BIT8       apply_scc_flag;   /* flag to enable expansion of the sig profile*/
   CCOMP_TYPE type;             /* type of signal profile                     */
   U_INT16  signal_count;
   U_INT16  segment_count;
   U_INT16  subsegment_count;
   INT32    value;
   INT32    prev_value;
   INT32    slope;             /* slope between interpolation points          */
   INT32    slope_rem;         /* remainder from slope calculation            */
   INT32    slope_rem_sum;     /* running sum of remainder from slope calc    */
   INT32    slope_divisor;     /* divisor used in slope calculation           */
   INT32    deriv2;            /* 2nd derivative between interpolation points */
   INT32    deriv2_rem;        /* remainder from 2nd derivative calculation   */
   INT32    deriv2_rem_sum;    /* running sum of remainder from 2nd deriv calc*/
   INT32    deriv2_divisor;    /* divisor used in 2nd derivative calculation  */
   INT32    scale_factor;      /* scale factor used for test plot generation  */
   pCCOMP_DATA pdata;          /* pointer to column compensation status var.s */
   PROFILE  *pprofile;         /* pointer to column compensation profile data */

} CCOMP_TABLE, *pCCOMP_TABLE;    /* struct name for column compensation table */

/*****************************/
/*   EXTERNALS               */
/*****************************/

extern  SIG_FILTER Sig1_Filt;         /* Filter for signal 1, for noisy sig.s */
extern  SIG_FILTER Sig2_Filt;         /* Filter for signal 2, for noisy sig.s */
extern  SIG_FILTER Deta_Filt;         /* Filter for detector A signal from dsp*/
extern  SIG_FILTER Detb_Filt;         /* Filter for detector B signal from dsp*/

extern  INT32 Sig1_Filt_Table[ARRAY_SIZE_SIG_DISP];
extern  INT32 Sig2_Filt_Table[ARRAY_SIZE_SIG_DISP];
extern  INT32 Deta_Filt_Table[ARRAY_SIZE_SCC_DET];
extern  INT32 Detb_Filt_Table[ARRAY_SIZE_SCC_DET];

extern  SIG_TABLE Signal1;            /* working copies of setpts and status  */
extern  SIG_TABLE Signal2;
extern  SIG_TABLE SignalP;
extern  SIG_TABLE *pSignal;           /* pointer to working setpts and status */

extern  CCOMP_TABLE Ccomp1;           /* column compenstation 1 working values*/
extern  CCOMP_TABLE Ccomp2;           /* column compenstation 2 working values*/
extern  CCOMP_TABLE Test_Plot;        /* test plot working values             */
extern  CCOMP_TABLE Test_Signal;      /* test signal working values           */

extern  const RATE_REC RATE_TABLE[];  /* conversion from data rate to bunch   */
                                      /* count and dsp data rate              */
extern  const char UNKNOWN_LABEL[];

#pragma SECTION DATA=pfail

extern  SIG_RUN_STATE Scc_Run_State;  /* run state of the scc profiles        */
extern  BIT8      Scc_Start_Pending;  /* flag to request a reset of expand scc*/

extern  CCOMP_DATA  Ccomp1_Data;      /* column compenstation 1 state         */
extern  CCOMP_DATA  Ccomp2_Data;      /* column compenstation 2 state         */
extern  CCOMP_DATA  Test_Plot_Data;   /* test plot state                      */
extern  CCOMP_DATA  Test_Signal_Data; /* test signal state                    */

extern        PROFILE Ccomp1_Profile;
extern        PROFILE Ccomp2_Profile;
extern  const PROFILE TEST_PLOT_PROFILE;
extern  const PROFILE TEST_PLOT_PROFILE2;
extern  const PROFILE TEST_SIG_PROFILE;

#pragma SECTION UNDO

#endif
